/**
 * Created with IntelliJ IDEA.
 * Description:
 * x:当前不重复串的长度
 * l:最大长度
 *
 */



public class TestDemo {

    static int lengthOfLongestSubstring(String s) {
        int l = 0;
        int i = 0;
        while (i < s.length()) {
            int x = s.indexOf(s.charAt(i));
            if (x < i) {
                s = s.substring(x + 1);
                i = i - x - 1;
            } else {
                i++;
            }
            l = Math.max(l, i);
        }
        return l;
    }

    public static void main(String[] args) {
        String str = "abcabcbb";
        int sum = lengthOfLongestSubstring(str);
        System.out.println(sum);
    }
}

